﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using crm_dal.Objects;
using crm_library.Javascript;

namespace crm_web.DataPages
{
    public partial class CreateFollowup : System.Web.UI.Page
    {
        Followup displayFollowUp;

		protected void Page_Init(object sender, EventArgs e)
		{
			if (!IsPostBack)
			{
				ddlUserID.Items.AddRange(crm_dal.Objects.User.GetAll().Select(user => user.ToListItem()).ToArray());
				ddlContactID.Items.AddRange(Contact.GetAll().Select(ctact => ctact.ToListItem()).ToArray());
			}
		}


        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                displayFollowUp = new Followup(Convert.ToInt32(HttpContext.Current.Session["Selection"]));
            }
            catch (Exception ex)
            {
                Alert.Show(ex.Message, Alert.AlertMessageType.Error);
            }
        }

        protected void btnCreate_Click(object sender, EventArgs e)
        {
            string error = "";
            try
            {
                displayFollowUp.UserID = Convert.ToInt32(ddlUserID.SelectedValue);
				displayFollowUp.ContactID = Convert.ToInt32(ddlContactID.SelectedValue);
                displayFollowUp.FollowupByDate = Convert.ToDateTime(txtFollowupByDate.Text);
                displayFollowUp.DateFollowedUpOn = Convert.ToDateTime(txtDateFollowedUpOn.Text);
                displayFollowUp.ResponseTypeInt = Convert.ToInt32(txtResponseType.Text);
                displayFollowUp.Notes = txtNotes.Text.Trim();
                displayFollowUp.Create();
            }
            catch (Exception ex)
            {
                error = ex.Message;
            }

            if (!String.IsNullOrWhiteSpace(error))
            {
                Alert.Show(error, Alert.AlertMessageType.Error);
            }
            else
            {
                Alert.Show("create succeeded", Alert.AlertMessageType.Message, "/DataPages/FollowUp.aspx");
            }

        }
    }
}